# rvmaster-c is a C++ implementation of RVMaster
# RVMaster listens to $ROS_MASTER_URI and connects to the
# real ROS master at $REAL_MASTER_URI
# 
# The access policies are configured in file "access-policy.cfg"
# Currently, we categorize the policies into three different sections: 
# [Commands], [Subscribers], and [Publishers]. 
# Under each section, the access policy is written as a key followed by
# an assignment symbol and a list of values: 
# 
# key = value1 value2 value3 ...
# 
# For [Subscribers] and [Publishers], "key" is the topic name, 
# and "value" is the hostname of the machine allowed to subscribe/publish 
# to the topic. For [Commands], "key" is the command name, "value" is the 
# name of the node allowed to perform the command. 
# 
# Following is a sample file:
# 
# ------------------------
# [Publishers]
# /chatter1=localhost fslwork
# [Subscribers]
# /chatter2=localhost fslwork fslexp
# [Commands]
# getSystemState=/listener1 /listener2
# getTopicTypes=/rosnode
# getPublishedTopics=/rosnode
# lookupNode /talker=/rosnode
# lookupService /talker=/rosnode
# --------------------------
# 
# For example, "/chatter1=localhost fslwork" means that only nodes running on 
# the machine "localhost" or "fslwork" can publish to the topic "/chatter1". 
# "getSystemState=/listener1 /listener2" means that only the nodes "/listener1" 
# and "/listener2" are allowed to call "getSystemState". 
# "/rosnode" is not allowed to call "getSystemState".
# 
# 
# Build: 
# -----------------
cd rvmaster-c
catkin_make
#  --------------------------------
# 
# Run without access control:
# ----------------------------------
# 1. within rvmaster-c directory, open seven terminals: T1, T2, T3, T4, T5, T6, T7
# 2. for each terminal, run "source devel/setup.sh"
# 3. choose a port number (e.g., 12345) for the ROS master and run "export REAL_MASTER_URI=http://localhost:12345"
# 4. do the following in the corresponding terminal:
# 
# T1 (run ROS master): roscore -p 12345
# T2 (run RV master): rosrun rvmaster rvmaster_master
# T3 (run publisher1 ): rosrun rvmaster_test talker1_program
# T4 (run publisher2 ): rosrun rvmaster_test talker2_program
# T5 (run subscriber1): rosrun rvmaster_test listener1_program
# T6 (run subscriber2): rosrun rvmaster_test listener2_program
# 
# You will see T5 receives the message from T3 (on topic "chatter1"), and T6 from T4 (on topic "chatter2"). 
# 
# T7: (kill nodes): rosnode kill -a
# 
# You will see the subscribers and publishers are all killed.
# -------------------------------------
# 
# 
# Run with access control
# ------------------------------------------------
# 1. run "export ACCESS_POLICY_PATH=${PWD}/access-policy.cfg" to set the path of the access policy file.
# 2. redo the steps in "run without access control"
# 
# You will see T5 can no longer receive message from T3, because it is not 
# allowed to subscribe to topic "chatter1" as specified in the access policy. 
# Similarly, T6 can no longer receive message from T4, because T4 is not 
# allowed to publish to the topic "chatter2". In addition, T7 will fail 
# to kill nodes, because it is not allowed to send "getSystemState" command 
# to the master.
# -------------------------------------------------------------------
# 
# 
# 
# 
# Read the following instruction on how to compile and run rvmaster
# 
# compile
catkin_make
source ./setup.sh
# 
# run
rosrun rvmaster rvmaster_master
